package com.wanmait.houlang.manageController;

import com.github.pagehelper.PageInfo;
import com.wanmait.houlang.pojo.DTO;
import com.wanmait.houlang.pojo.School;
import com.wanmait.houlang.service.SchoolService;
import com.wanmait.houlang.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/manage")
public class ManageSchoolController {

    @Resource
    private SchoolService schoolService;

    //所有学校信息
    @GetMapping("schoolList")
    public Result findAllSchool(){
        DTO dto = new DTO();
        PageInfo<School> schoolList = schoolService.findAll(1,5,dto);
        return Result.success(schoolList);
    }

    //管理员查询所有学校信息(分页）
    @PostMapping("schools")
    @ResponseBody
    public Result ListPage(Integer pageNum){
        DTO dto = new DTO();
        PageInfo<School> schoolList = schoolService.findAll(pageNum,2,dto);
        return Result.success(schoolList);
    }

    //管理员搜索学校
    @PostMapping("searchSchool")
    @ResponseBody
    public Result searchSchoolByName(Integer pageNum,String schoolName){
        DTO dto = new DTO();
        dto.setSchoolName(schoolName);
        PageInfo<School> schools = schoolService.searchSchoolByName(pageNum,1,dto);
        return Result.success(schools);
    }
}
